
<?php
if(isset($_POST['modifierCompte'])){
    if(sha1($_POST['oldPassword']) == $_SESSION['password']){
        $infos = $this->modifierCompte();
        echo "<pre class='success'>$infos</pre>";
    } else {
        echo '<pre class="erreurs">Mot de passe incorrecte veuillez recommencer !</pre>';
    }

} else if(isset($_POST['modifierInfos'])){
    $infos = $this->modifierInfos();
}

if(!empty($this->request->params) && $this->request->params[0]=="compte"){
    ?>
    <form method="post" id="monForm" >
        <div class="titre_h1"><h1>Mise à jour du compte</h1></div>

        <div class="legend_formulaire"><legend>Modification du compte</legend></div>

        <table class="table table-hover">
            <tr>
                <td><label for="email">Email: </label>
                </td>
                <td><input type="email" name="email" value="<?php echo $_SESSION['email'] ?>" required class="form-control"/>
                </td>
            </tr>
            <tr>
                <td><label  for="password">Nouveau mot de passe : </label></td>
                <td><input type="password" name="newPassword" placeholder='*********' class="form-control"/></td>
            </tr>
            <tr>
                <td><label  for="password">Confirmez : </label></td>
                <td><input type="password" name="newPasswordConf" placeholder='*********' class="form-control"/></td>
            </tr>
            <tr>
                <td><label>Ancien mot de passe : </label></td>
                <td><input type="password" required name="oldPassword" class="form-control" /></td>
            </tr>
        </table>
        <button class="btn btn-success"  type="submit" name="modifierCompte">Enregistrer</button>
        <button class="btn btn-danger"  type="reset">Par défaut</button>
    </form>

<?php
} else if(!empty($this->request->params) && $this->request->params[0]=="infos") {
    $donnee = $this->getInfosReso();
    $traiteur = $donnee['traiteur'];
    $adresse = $donnee['adresse'];

    ?>
    <form method="post" onSubmit="return verifInfos()" />
    <div class="titre_h1"><h1>Mise à jour du profil</h1></div>

    <input type="hidden" name="pays" value="<?php echo $adresse->pays ?>" />
    <div class="legend_formulaire"><legend>Informations</legend></div>
    <table class="table table-hover">
        <tr>
            <td><label>Nom du traiteur</label></td>
            <td><input type="text" value="<?php echo $traiteur->nom_restaurant; ?>" name="nom"  class="form-control"
                       id="nom" required/>
            </td>
        </tr>
        <tr>
            <td><label>Téléphone </label></td>
            <td><input type="tel" value="<?php echo $traiteur->telephone_restaurant;?>" name="telephone" class="form-control"
                       id="telephone" required/></td>
        </tr>
        <tr>
            <td><label>Email </label></td>
            <td><input type="text" value="<?php echo $traiteur->email_restaurant != "" ? $traiteur->
                    email_traiteur : "Non renseigné"  ?>" name="email" id="email" class="form-control"/></td>
        </tr>
        <tr>
            <td><label>Site internet </label></td>
            <td><input type="text" value="<?php echo $resto->site_traiteur==""? "Non renseigné" :
                    $resto->site_traiteur?>" name="site" id="site" class="form-control"/>
            </td>
        </tr>
        <tr>
            <td><label>Description </label></td>
            <td><textarea name="description" class="form-control"><?php echo $traiteur->description_traiteur=="" ?
                        "Aucune description..." : $traiteur->description_traiteur?></textarea></td>
        </tr>

    </table>

    <div class="legend_formulaire"><legend>Adresse du traiteur</legend></div>
    <table class="table table-hover">
        <tr>
            <td><label for="adresse">Adresse </label></td>
            <td><input type="text" name="adresse" value="<?php echo $adresse->adresse ?>" class="form-control"
                       id="adresse" required /></td>
        </tr>
        <tr>
            <td><label  for="code_postal">Code Postal </label></td>
            <td><input type="number" name="code_postal" value="<?php echo $adresse->code_postal ?>"required
                       class="form-control" /></td>
        </tr>
        <tr>
            <td><label  for="ville">Ville : </label></td>
            <td><input type="text" name="ville" value="<?php echo $adresse->ville ?>" required class="form-control"
                       pattern="^[a-zA-Zéàèù- ]+$"/></td>
        </tr>
    </table>




    <button class="btn btn-success"  type="submit" name="modifierInfos" >Enregistrer</button>
    <button class="btn btn-danger"  type="reset" >Par défaut</button>

    </form>
<?php
}
?>

